package com.yjhealth.libs.businessdemo.business;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

import com.yjhealth.libs.businessdemo.R;
import com.yjhealth.libs.commonlib.base.activity.BaseActivity;
import com.yjhealth.libs.commonlib.web.CommonWebActivity;
import com.yjhealth.libs.commonlib.web.CommonWebFragment;
import com.yjhealth.libs.core.core.activity.CoreActivity;

public class DemoWebFragmentActivity extends BaseActivity {
    private Fragment currentFragment;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.businessdemo_activity_demo_web_fragment);

        initLayout();

//        switchFragment(CommonWebFragment.newInstance("http://app.dev.aijk.net/index.html" + CommonWebActivity.getCommonParam(false)));
        switchFragment(CommonWebFragment.newInstance("https://cyhk.smlh5.esign.cn/forward-faceauth/tsign/face/callback/a54ce05e75a44c20a2e3bdfc7267b75d/1039110457572460257?orderNo=2019121801999077375&signature=35389DFA89727DBA79784B730F0FC742FFE41339&code=-5011&newSignature=C1EFE96374B29E564222099626AB0310E66318C3&h5faceId=b62c82e70e4880f471c5758b1386c41b"));
    }

    @Override
    protected void onRefreshView() {

    }

    private void switchFragment(Fragment targetFragment) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        if (!targetFragment.isAdded()) {
            if (currentFragment != null) {
                transaction.hide(currentFragment);
            }
            transaction.add(R.id.flFragment, targetFragment, targetFragment.getClass().getName());
        } else {
            transaction.hide(currentFragment).show(targetFragment);
        }
        currentFragment = targetFragment;
        transaction.commitAllowingStateLoss();
    }
}
